package com.pengshun.modules.api.order.service.impl;

import com.pengshun.modules.api.order.repository.MerchantEvaluateRepository;
import com.pengshun.modules.api.order.service.MerchantEvaluateService;
import com.pengshun.modules.api.order.service.dto.MerchantEvaluateDto;
import com.pengshun.modules.api.order.service.mapstruct.MerchantEvaluateTodo;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.MerchantEvaluate;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@RequiredArgsConstructor
public class MerchantEvaluateServiceImpl implements MerchantEvaluateService {

    private final MerchantEvaluateRepository merchantEvaluateRepository;
    private final MerchantEvaluateTodo merchantEvaluateTodo;

    @Override
    public BaseResult addComments(MerchantEvaluateDto para) {
        para.setCreateTime(new Date());
        para.setStatus(1);
        merchantEvaluateRepository.save(merchantEvaluateTodo.toEntity(para));
        return new BaseResult(0);
    }

    @Override
    public BaseResult deleteComments(MerchantEvaluateDto para) {
        MerchantEvaluate byId = merchantEvaluateRepository.findById(para.getMerchantEvaluateId()).orElseGet(MerchantEvaluate::new);
        byId.setStatus(2);
        merchantEvaluateRepository.save(byId);
        return new BaseResult(0);
    }
}
